package com.hxzy.tms.aciton;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.hxzy.tms.entity.Team;
import com.hxzy.tms.entity.TeamUser;
import com.hxzy.tms.entity.User;
import com.hxzy.tms.entity.UserTask;
import com.hxzy.tms.service.TaskService;
import com.hxzy.tms.service.TeamService;
import com.hxzy.tms.service.UserService;

public class UserAction extends AbstractAction {
    private static final long serialVersionUID = -3897815079838663115L;
    private String id;

    private UserService userService;
    private TeamService teamService;
    private TaskService taskService;

    public String index() {
        if (id == null || StringUtils.isBlank(id)) {
            return _404();
        }
        Long _id = new Long(id);
        // 基本信息
        User user = userService.read(_id).data;
        if (user == null) {
            return _404();
        }
        assign("user", user);

        // 创建的团队
        List<Team> teams = teamService.userCreateTeams(_id, null).data;
        assign("teams", teams);

        // 加入的团队
        List<TeamUser> userTeams = teamService.userJoinedTeams(_id).data;
        assign("userTeams", userTeams);

        // 任务以及任务的状态
        List<UserTask> userTasks = taskService.list(_id).data;
        assign("userTasks", userTasks);

        return INPUT;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public TeamService getTeamService() {
        return teamService;
    }

    public void setTeamService(TeamService teamService) {
        this.teamService = teamService;
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public TaskService getTaskService() {
        return taskService;
    }

    public void setTaskService(TaskService taskService) {
        this.taskService = taskService;
    }

}
